web/src/pages/inventory/[...inventoryId].astro
105 lines · 2442 bytes
1---
2import Layout from '@layouts/Layout.astro';
3import SavedServices from '@components/things/SavedServices.svelte';
4
5import { fetchData } from '@utils/fetch-data';
6import Button from '@components/form/Button.astro';
7import type { Category } from '../../types/Service';
8
9const categories = (await fetchData())?.categories || ([] as Category[]);
10
11export const prerender = false;
12
13const inventoryId = Astro.params.inventoryId || 'Inventory';
14let cheekyLilError = '';
15
16function makeTitle(input: string): string {
17 return (input.includes('_') ? input : `mystry_${input}`)
18 .split('_')[1]
19 .replace(/-/g, ' ')
20 .replace(/\b\w/g, (match) => match.toUpperCase());
21}
22
23const serviceList =
24 (await fetch(
25 `https://awesome-privacy-share-api.as93.net/${inventoryId}`,
26 ).then((res) => res.json())) || [];
27
28if (serviceList.error) {
29 cheekyLilError = serviceList.error;
30}
31---
32
33<Layout title="Saved Services">
34 <main>
35 <h2>{makeTitle(inventoryId)}</h2>
36 {
37 cheekyLilError && (
38 <div class="error">
39 <p class="oh-deary-me">An error occoured</p>
40 <p class="what-the-fuck-happened">{cheekyLilError}</p>
41 <p class="what-next">
42 We're sorry about that.
43 <br />
44 Try going <a href="/">back home</a>, or{' '}
45 <a href="https://github.com/Lissy93/awesome-privacy/issues/new/choose">
46 raising a ticket
47 </a>{' '}
48 on GitHub.
49 </p>
50 </div>
51 )
52 }
53 <SavedServices allData={categories} serviceList={serviceList} client:load />
54 <div class="buttons">
55 <p>Not found what you're looking for?</p>
56 <Button url="/all">Browse Services</Button>
57 </div>
58 </main>
59</Layout>
60
61<style lang="scss">
62 main {
63 margin: 0 auto 2rem auto;
64 padding: 1rem;
65 width: 1200px;
66 max-width: calc(100% - 5rem);
67 display: flex;
68 justify-content: space-between;
69 flex-direction: column;
70 min-height: calc(100vh - 12rem);
71 font-size: 1.25rem;
72 h2 {
73 font-family: 'Lekton', sans-serif;
74 font-weight: bold;
75 font-size: 3rem;
76 margin: 0;
77 color: var(--accent-3);
78 }
79 .buttons {
80 margin: 1rem auto;
81 display: flex;
82 flex-direction: column;
83 }
84 .error {
85 text-align: center;
86 font-size: 1.4rem;
87 .oh-deary-me {
88 font-size: 1.8rem;
89 margin: 0.2rem auto;
90 }
91 .what-the-fuck-happened {
92 color: var(--danger);
93 margin: 0.2rem auto;
94 }
95 .what-next {
96 font-size: 1rem;
97 margin-top: 3rem;
98 opacity: 0.6;
99 a {
100 color: var(--foreground);
101 }
102 }
103 }
104 }
105</style>